package com.zqxx.examine.common.utils;


import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Page<T>
{
  private int pageNo = 1;
  private int pageSize = 10;
  private int totalRecord;
  private int totalPage;
  private boolean getAllRecord;
  private List<T> results;
  private Map<String, Object> params = new HashMap();
  
  public boolean isGetAllRecord()
  {
    return this.getAllRecord;
  }
  
  public void setGetAllRecord(boolean getAllRecord)
  {
    this.getAllRecord = getAllRecord;
  }
  
  public int getPageNo()
  {
    return this.pageNo;
  }
  
  public void setPageNo(int pageNo)
  {
    this.pageNo = pageNo;
  }
  
  public int getPageSize()
  {
    return this.pageSize;
  }
  
  public void setPageSize(int pageSize)
  {
    this.pageSize = pageSize;
  }
  
  public int getTotalRecord()
  {
    return this.totalRecord;
  }
  
  public void setTotalRecord(int totalRecord)
  {
    this.totalRecord = totalRecord;
    
    int totalPage = totalRecord % this.pageSize == 0 ? totalRecord / this.pageSize : totalRecord / this.pageSize + 1;
    if (totalPage == 0) {
      totalPage = 1;
    }
    setTotalPage(totalPage);
    if (this.pageNo <= 0) {
      setPageNo(1);
    }
    if (this.pageNo > this.totalPage) {
      this.pageNo = this.totalPage;
    }
  }
  
  public int getTotalPage()
  {
    return this.totalPage;
  }
  
  public void setTotalPage(int totalPage)
  {
    this.totalPage = totalPage;
  }
  
  public List<T> getResults()
  {
    return this.results;
  }
  
  public void setResults(List<T> results)
  {
    this.results = results;
  }
  
  public Map<String, Object> getParams()
  {
    return this.params;
  }
  
  public void setParams(Map<String, Object> params)
  {
    this.params = params;
  }
  
  public String toString()
  {
    StringBuilder builder = new StringBuilder();
    builder.append("Page [pageNo=").append(this.pageNo).append(", pageSize=")
      .append(this.pageSize).append(", results=").append(this.results)
      .append(", totalPage=").append(this.totalPage)
      .append(", totalRecord=").append(this.totalRecord).append("]");
    return builder.toString();
  }
}
